import axios from 'axios'

// 使用与用户模块相同的API基础地址
const baseURL = 'http://localhost:40321/api'

// 创建 axios 实例
const request = axios.create({
  baseURL,
  withCredentials: true // 允许携带凭证
})

// 获取有趣网页列表
export const getWebpageList = async () => {
  try {
    const response = await request.get('/webpage/list')
    return response.data
  } catch (error) {
    console.error('API请求错误:', error)
    throw error.response?.data || error
  }
}

// 根据ID获取网页详情
export const getWebpageById = async (id) => {
  try {
    const response = await request.get(`/webpage/get?id=${id}`)
    return response.data
  } catch (error) {
    throw error.response?.data || error
  }
}

// 获取下载网页压缩包的URL
export const getWebpageDownloadUrl = (id) => {
  return `${baseURL}/webpage/download/${id}`
}


